/*
' Copyright (c) 2010 DotNetNuke Corporation
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 
*/

using System.Collections.Generic;
//using System.Xml;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Modules.AjaxWebLinks.Data;

namespace DotNetNuke.Modules.AjaxWebLinks.Components
{

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The Controller class for AjaxWebLinks
    /// </summary>
    /// -----------------------------------------------------------------------------
    public class AjaxWebLinksController 
    {

        
        #region Public Methods
        public List<AjaxWebLinkInfo> GetLinks(int ModuleId)
        {
            return CBO.FillCollection<AjaxWebLinkInfo>(DataProvider.Instance().GetLinks(ModuleId));
        }

        public AjaxWebLinkInfo GetLink(int ModuleId, int LinkID)
        {
            return (AjaxWebLinkInfo)CBO.FillObject(DataProvider.Instance().GetLink(ModuleId, LinkID), typeof(AjaxWebLinkInfo));
        }

        public int AddLink(AjaxWebLinkInfo link)
        {
            
            if ( link.LinkText.Trim()!= string.Empty && link.LinkURL.Trim() != string.Empty )
            {
               return DataProvider.Instance().AddLink(link.ModuleId,link.LinkURL, link.LinkText);
            }
            return 0;

        }

        public void UpdateLink(AjaxWebLinkInfo link)
        {
            if (link.LinkText.Trim() != string.Empty && link.LinkURL.Trim() != string.Empty)
            {
                DataProvider.Instance().UpdateLink(link.ModuleId, link.LinkID, link.LinkURL, link.LinkText);
            }
        }

        public void DeleteLink(int ModuleId, int linkID)
        {
            DataProvider.Instance().DeleteLink(ModuleId, linkID);
        }


        #endregion


    }

}
